if(!JObj.Plugin) JObj.Plugin = {};
JObj.Plugin.JImgLoader = {};
(function($){
	var loader = null;
	var id = (((new Date()).valueOf() * 100000) + Math.random() * 100000).toString(32);
	
	var path = JObj.Loader.getFullPath(JObj.path + "plugins/JImgLoader/loader.swf");
	var str = "";
	
	if(JObj.Browser.ie){
		str = '<OBJECT id="{#id}" codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" height="1" width="1" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"><PARAM NAME="Src" VALUE="{#path}"><PARAM NAME="AllowScriptAccess" VALUE="always"><PARAM NAME="AllowNetworking" VALUE="all"></OBJECT>';
	}else{
		str = '<embed width="1" height="1" type="application/x-shockwave-flash" allowscriptaccess="always" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" quality="high" src="{#path}" name="{#id}"/>';	
	}
	var t = JObj.$c("SPAN");
	document.body.appendChild(t);
	t.innerHTML = str.replace(/\{#id\}/g,id).replace(/\{#path\}/g,path);
	
	if(JObj.Browser.ie)
		t.style.display="none";//FF下不可以为 none
	
	if(JObj.Browser.ie){
		loader = window[id];
	}else{
		loader = document[id];
	}	
	
	/**
	rule:
	{url:xxx,onStart:fun,onProcess:fun,onCompete:fun,onError:fun}
	*/
	
	var rules = {};
	
	$.load = function(rule){
		var uniID = (((new Date()).valueOf() * 100000) + Math.random() * 100000).toString(32);
		rules[uniID] = rule;
		loader.loadImg(rule.url,uniID);
	}
	
	$._onStart = function(url,uniID){
		var rule = rules[uniID];
		if(JObj.isFunction(rule.onStart)) rule.onStart(url,rule);
	}
	
	$._onProcess = function(url,uniID,loadedBytes,totalBytes){
		var rule = rules[uniID];
		if(JObj.isFunction(rule.onProcess)) rule.onProcess(url,loadedBytes,totalBytes,rule);
	}
	
	$._onComplete = function(url,uniID,status,width,height){
		var rule = rules[uniID];
		if(JObj.isFunction(rule.onComplete)) rule.onComplete(url,status,width,height,rule);
		delete rules[uniID];
	}
	
	$._onError = function(url,uniID,status,errorCode){
		var rule = rules[uniID];
		if(JObj.isFunction(rule.onError)) rule.onError(url,status,errorCode,rule);
	}
})(JObj.Plugin.JImgLoader);